﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

using RemoteScriptingLibrary;
using RemoteScriptingLibrary.ScriptCommands;

namespace WindowsRemoteScripting
{
    public partial class CommandHelp : Form
    {
        public CommandHelp()
        {
            InitializeComponent();
            SortedDictionary<string, List<int>> aCommand = AssemblyHelper.GetCommandsFromType(typeof(Script));
            foreach(KeyValuePair<string, List<int>> keyValuePair in aCommand)
            {
                this.lbCommands.Items.Add(keyValuePair.Key);
            }
        }

        private void lbCommands_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sMethod = this.lbCommands.Items[this.lbCommands.SelectedIndex].ToString();

            MethodInfo methodInfo = null;

            //Found no other solution for this yet if method is overloaded
            try
            {
                methodInfo = typeof(Script).GetMethod(sMethod);
            }
            catch (Exception ex)
            {
                methodInfo = typeof(Script).GetMethod(sMethod, new Type[] { });
            }

            string sText = AssemblyHelper.PrintMethodInfo(methodInfo);
            // string sText = AssemblyHelper.PrintMethodInfo(typeof(Script).GetMethod(sMethod, BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly));
            label1.Text = sText;
        }
    }
}
